
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/28/2011 13:08:39
-- Generated from EDMX file: G:\Dotnet\code\UserDefineForm\svn\implement\UserDefineForm\UserDefineForm\dao\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [UserDefineForm];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'OrderForms'
CREATE TABLE [dbo].[OrderForms] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'OrderedComponents'
CREATE TABLE [dbo].[OrderedComponents] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [OrderForm_Id] int  NOT NULL
);
GO

-- Creating table 'ListItems'
CREATE TABLE [dbo].[ListItems] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Control_Id] int  NOT NULL
);
GO

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OrderForm_Id] int  NOT NULL
);
GO

-- Creating table 'OrderFormControls'
CREATE TABLE [dbo].[OrderFormControls] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OrderForm_Id] int  NOT NULL
);
GO

-- Creating table 'SupplierOrders'
CREATE TABLE [dbo].[SupplierOrders] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SupplierOrderForm_Id] int  NOT NULL,
    [Order_Id] int  NOT NULL
);
GO

-- Creating table 'OrderControlDatas'
CREATE TABLE [dbo].[OrderControlDatas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Order_Id] int  NOT NULL,
    [OrderFormControl_Id] int  NOT NULL
);
GO

-- Creating table 'SupFormControlDatas'
CREATE TABLE [dbo].[SupFormControlDatas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [SupplierOrder_Id] int  NOT NULL,
    [SupFormControl_Id] int  NOT NULL
);
GO

-- Creating table 'SupplierOrderForms'
CREATE TABLE [dbo].[SupplierOrderForms] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Status] int  NULL,
    [Background] varbinary(max)  NULL,
    [OrderedComponent_Id] int  NOT NULL
);
GO

-- Creating table 'SupFormControls'
CREATE TABLE [dbo].[SupFormControls] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DefaultValue] nvarchar(max)  NULL,
    [Font] nvarchar(max)  NOT NULL,
    [Height] int  NOT NULL,
    [Left] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Status] int  NULL,
    [SummaryField] nvarchar(max)  NULL,
    [TooltipText] nvarchar(max)  NULL,
    [Top] int  NOT NULL,
    [Type] int  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Width] int  NOT NULL,
    [IsSummaryAvailable] bit  NOT NULL,
    [SupplierForm_Id] int  NOT NULL,
    [SummaryCollumns_Id] int  NOT NULL
);
GO

-- Creating table 'SummaryCollumns'
CREATE TABLE [dbo].[SummaryCollumns] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [OrderedComponent_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'OrderForms'
ALTER TABLE [dbo].[OrderForms]
ADD CONSTRAINT [PK_OrderForms]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrderedComponents'
ALTER TABLE [dbo].[OrderedComponents]
ADD CONSTRAINT [PK_OrderedComponents]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ListItems'
ALTER TABLE [dbo].[ListItems]
ADD CONSTRAINT [PK_ListItems]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrderFormControls'
ALTER TABLE [dbo].[OrderFormControls]
ADD CONSTRAINT [PK_OrderFormControls]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SupplierOrders'
ALTER TABLE [dbo].[SupplierOrders]
ADD CONSTRAINT [PK_SupplierOrders]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrderControlDatas'
ALTER TABLE [dbo].[OrderControlDatas]
ADD CONSTRAINT [PK_OrderControlDatas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SupFormControlDatas'
ALTER TABLE [dbo].[SupFormControlDatas]
ADD CONSTRAINT [PK_SupFormControlDatas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SupplierOrderForms'
ALTER TABLE [dbo].[SupplierOrderForms]
ADD CONSTRAINT [PK_SupplierOrderForms]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SupFormControls'
ALTER TABLE [dbo].[SupFormControls]
ADD CONSTRAINT [PK_SupFormControls]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SummaryCollumns'
ALTER TABLE [dbo].[SummaryCollumns]
ADD CONSTRAINT [PK_SummaryCollumns]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [SupplierForm_Id] in table 'SupFormControls'
ALTER TABLE [dbo].[SupFormControls]
ADD CONSTRAINT [FK_SupplierFormControl]
    FOREIGN KEY ([SupplierForm_Id])
    REFERENCES [dbo].[SupplierOrderForms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SupplierFormControl'
CREATE INDEX [IX_FK_SupplierFormControl]
ON [dbo].[SupFormControls]
    ([SupplierForm_Id]);
GO

-- Creating foreign key on [Control_Id] in table 'ListItems'
ALTER TABLE [dbo].[ListItems]
ADD CONSTRAINT [FK_ControlListItem]
    FOREIGN KEY ([Control_Id])
    REFERENCES [dbo].[SupFormControls]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ControlListItem'
CREATE INDEX [IX_FK_ControlListItem]
ON [dbo].[ListItems]
    ([Control_Id]);
GO

-- Creating foreign key on [OrderedComponent_Id] in table 'SupplierOrderForms'
ALTER TABLE [dbo].[SupplierOrderForms]
ADD CONSTRAINT [FK_OrderedComponentSupplierOrderForm]
    FOREIGN KEY ([OrderedComponent_Id])
    REFERENCES [dbo].[OrderedComponents]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderedComponentSupplierOrderForm'
CREATE INDEX [IX_FK_OrderedComponentSupplierOrderForm]
ON [dbo].[SupplierOrderForms]
    ([OrderedComponent_Id]);
GO

-- Creating foreign key on [OrderForm_Id] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_OrderFormOrder]
    FOREIGN KEY ([OrderForm_Id])
    REFERENCES [dbo].[OrderForms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderFormOrder'
CREATE INDEX [IX_FK_OrderFormOrder]
ON [dbo].[Orders]
    ([OrderForm_Id]);
GO

-- Creating foreign key on [OrderForm_Id] in table 'OrderFormControls'
ALTER TABLE [dbo].[OrderFormControls]
ADD CONSTRAINT [FK_OrderFormOrderFormControl]
    FOREIGN KEY ([OrderForm_Id])
    REFERENCES [dbo].[OrderForms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderFormOrderFormControl'
CREATE INDEX [IX_FK_OrderFormOrderFormControl]
ON [dbo].[OrderFormControls]
    ([OrderForm_Id]);
GO

-- Creating foreign key on [SupplierOrderForm_Id] in table 'SupplierOrders'
ALTER TABLE [dbo].[SupplierOrders]
ADD CONSTRAINT [FK_SupplierOrderFormSupplierOrder]
    FOREIGN KEY ([SupplierOrderForm_Id])
    REFERENCES [dbo].[SupplierOrderForms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SupplierOrderFormSupplierOrder'
CREATE INDEX [IX_FK_SupplierOrderFormSupplierOrder]
ON [dbo].[SupplierOrders]
    ([SupplierOrderForm_Id]);
GO

-- Creating foreign key on [OrderForm_Id] in table 'OrderedComponents'
ALTER TABLE [dbo].[OrderedComponents]
ADD CONSTRAINT [FK_OrderFormOrderedComponent]
    FOREIGN KEY ([OrderForm_Id])
    REFERENCES [dbo].[OrderForms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderFormOrderedComponent'
CREATE INDEX [IX_FK_OrderFormOrderedComponent]
ON [dbo].[OrderedComponents]
    ([OrderForm_Id]);
GO

-- Creating foreign key on [Order_Id] in table 'SupplierOrders'
ALTER TABLE [dbo].[SupplierOrders]
ADD CONSTRAINT [FK_OrderSupplierOrder]
    FOREIGN KEY ([Order_Id])
    REFERENCES [dbo].[Orders]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderSupplierOrder'
CREATE INDEX [IX_FK_OrderSupplierOrder]
ON [dbo].[SupplierOrders]
    ([Order_Id]);
GO

-- Creating foreign key on [SupplierOrder_Id] in table 'SupFormControlDatas'
ALTER TABLE [dbo].[SupFormControlDatas]
ADD CONSTRAINT [FK_SupplierOrderSupFormControlData]
    FOREIGN KEY ([SupplierOrder_Id])
    REFERENCES [dbo].[SupplierOrders]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SupplierOrderSupFormControlData'
CREATE INDEX [IX_FK_SupplierOrderSupFormControlData]
ON [dbo].[SupFormControlDatas]
    ([SupplierOrder_Id]);
GO

-- Creating foreign key on [SupFormControl_Id] in table 'SupFormControlDatas'
ALTER TABLE [dbo].[SupFormControlDatas]
ADD CONSTRAINT [FK_SupFormControlSupFormControlData]
    FOREIGN KEY ([SupFormControl_Id])
    REFERENCES [dbo].[SupFormControls]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SupFormControlSupFormControlData'
CREATE INDEX [IX_FK_SupFormControlSupFormControlData]
ON [dbo].[SupFormControlDatas]
    ([SupFormControl_Id]);
GO

-- Creating foreign key on [Order_Id] in table 'OrderControlDatas'
ALTER TABLE [dbo].[OrderControlDatas]
ADD CONSTRAINT [FK_OrderOrderControlData]
    FOREIGN KEY ([Order_Id])
    REFERENCES [dbo].[Orders]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderOrderControlData'
CREATE INDEX [IX_FK_OrderOrderControlData]
ON [dbo].[OrderControlDatas]
    ([Order_Id]);
GO

-- Creating foreign key on [OrderFormControl_Id] in table 'OrderControlDatas'
ALTER TABLE [dbo].[OrderControlDatas]
ADD CONSTRAINT [FK_OrderFormControlOrderControlData]
    FOREIGN KEY ([OrderFormControl_Id])
    REFERENCES [dbo].[OrderFormControls]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderFormControlOrderControlData'
CREATE INDEX [IX_FK_OrderFormControlOrderControlData]
ON [dbo].[OrderControlDatas]
    ([OrderFormControl_Id]);
GO

-- Creating foreign key on [SummaryCollumns_Id] in table 'SupFormControls'
ALTER TABLE [dbo].[SupFormControls]
ADD CONSTRAINT [FK_SupFormControlSummaryCollumn]
    FOREIGN KEY ([SummaryCollumns_Id])
    REFERENCES [dbo].[SummaryCollumns]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SupFormControlSummaryCollumn'
CREATE INDEX [IX_FK_SupFormControlSummaryCollumn]
ON [dbo].[SupFormControls]
    ([SummaryCollumns_Id]);
GO

-- Creating foreign key on [OrderedComponent_Id] in table 'SummaryCollumns'
ALTER TABLE [dbo].[SummaryCollumns]
ADD CONSTRAINT [FK_OrderedComponentSummaryCollumn]
    FOREIGN KEY ([OrderedComponent_Id])
    REFERENCES [dbo].[OrderedComponents]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderedComponentSummaryCollumn'
CREATE INDEX [IX_FK_OrderedComponentSummaryCollumn]
ON [dbo].[SummaryCollumns]
    ([OrderedComponent_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------